# Cross compiling.
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(GCC-PREFIX "arm-none-eabi-")
set(CMAKE_C_COMPILER ${GCC-PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${GCC-PREFIX}g++)
set(CMAKE_SIZE ${GCC-PREFIX}size)
set(CMAKE_STRIP ${GCC-PREFIX}strip)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(MCU -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard)
set(OPT -Og)

add_compile_options(
  ${MCU} ${OPT}
  -Wall -fdata-sections -ffunction-sections

  "$<$<OR:$<CONFIG:DEBUG>,$<NOT:$<BOOL:$<CONFIG>>>>:-O0;-g3;-DDEBUG>"
  "$<$<CONFIG:MINSIZEREL>:-Os;-DNDEBUG>"
  "$<$<CONFIG:RELEASE>:-O3;-DNDEBUG>"
  "$<$<CONFIG:RELWITHDEBINFO>:-O2;-g3;-DNDEBUG>"
)

SET(CMAKE_DE)

add_link_options(
  ${MCU} ${OPT}
  -specs=nano.specs -Wl,--gc-sections
)

if($<OR:$<CONFIG:DEBUG>,$<NOT:$<BOOL:$<CONFIG>>>>)
  message("xxxxxxxxxxxxxxxxxxxxxxxxxxx")
endif()